package com.gf.demo.weblogdemo.controller;

import com.gf.framework.weblog.annotation.WebLog;
import io.swagger.annotations.Api;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * @author gaofei
 * @date 2022/6/14 20:59
 */
@RestController
@Api(tags = "hello")
public class HelloController {
    @WebLog
    @GetMapping("hello")
    public String hello() throws InterruptedException {
        Random random = new Random();
        int n = Math.abs(random.nextInt() % 5);
        Thread.sleep(n * 1000);
        return "hello";
    }

    @Data
    public static class People {
        private Integer age;
        private String name;
    }

    @WebLog
    @PostMapping("post")
    public String post(@RequestBody People people) {
        Random random = new Random();
        if (random.nextInt() % 2 == 0) {
            int i = 10 / 0;
        }

        return people.toString();
    }
}
